package main

import (
	"fmt"
	"time"
)

type Book struct {
	Id          int
	Name        string
	Author      string
	PublishTime time.Time
}

func main() {
	// 1 属性全部初始化
	fmt.Println(Book{
		Id:          657,
		Name:        "无聊至极",
		Author:      "我",
		PublishTime: time.Now(),
	})

	fmt.Printf("\n\n\n")
	// 2 创建对象 制定field
	book1 := Book{
		Id:   12,
		Name: "go语言程序设计",
	}
	fmt.Println(book1)
	fmt.Printf("\n\n\n")

	// 3 不制定值
	fmt.Println(Book{})
	fmt.Printf("\n\n\n")

	//4 指针初始化
	var ptrBook *Book = &Book{
		Id:          980,
		Name:        "算法",
		Author:      "徐冬成",
		PublishTime: time.Now(),
	}
	fmt.Println("*ptrBook : ", *ptrBook)

	ptrBook2 := &Book{
		Id:          980,
		Name:        "算法",
		Author:      "徐冬成",
		PublishTime: time.Now(),
	}
	fmt.Println("*ptrBook : ", *ptrBook2)
	fmt.Printf("\n\n\n")

	// 5 new 分配指针初始化
	p := new(Book) // p为指针类型
	p.Name = "kafka源码分析"
	fmt.Println("p = ", p)
	fmt.Println("*p = ", *p)
	fmt.Printf("\n\n\n")

	// 类型
	fmt.Printf("book1 type is %T\n", book1)
	fmt.Printf("*ptrBook type is %T\n", ptrBook)
}
